package com.rivulet.doj_backend.service.impl;

import com.rivulet.doj_backend.mapper.CompetitionMapper;
import com.rivulet.doj_backend.service.CompetitionService;
import com.rivulet.doj_backend.tools.ResultFul;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompetitionServiceImpl implements CompetitionService {

    @Autowired
    CompetitionMapper competitionMapper;

    @Override
    public List<String> getCompetition(Integer user_id) {
        Integer result=404;
        List<String> competition = null;
        try {
            competition = competitionMapper.getCompetitionIdByUserId(user_id);
        }catch (Exception e){
            System.out.println(e);
        }finally {
            return competition;
        }
    }

    @Override
    public ResultFul addCompetition(Integer competition_id, Integer user_id){
        ResultFul result;
        try{
            if(user_id != null && competition_id != null) {
                competitionMapper.addCompetition(competition_id, user_id);
                result = new ResultFul<Object>(100, null);
            }else {
                result = new ResultFul<Object>(409, null);
            }
        }catch (Exception e) {
            System.out.println("addCompetition_error:" + e);
            result = new ResultFul<Object>(404, null);
        }

        return result;

    }
}
